<template>
	<el-card>
		<el-form :inline="true">
			<el-form-item>
				<vue-button :button-opr="constant.ButtonTypeMap.AddKey" button-text="新增" @emit-event="addOrUpdateHandle()"></vue-button>
			</el-form-item>
		</el-form>
		<el-table :v-loading="state.dataListLoading" :data="state.dataList" row-key="id" border style="width: 100%">
			<el-table-column prop="name" label="名称" header-align="center"></el-table-column>
			<el-table-column prop="sort" label="排序" header-align="center" align="center"></el-table-column>
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<vue-button :button-link=true :button-opr="constant.ButtonTypeMap.UpdateKey" button-text="修改" @emit-event="addOrUpdateHandle(scope.row.id)"></vue-button>
					<vue-button :button-link=true :button-opr="constant.ButtonTypeMap.DeleteKey" button-text="删除" @emit-event="deleteHandle(scope.row.id)"></vue-button>
				</template>
			</el-table-column>
		</el-table>
		<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList"></add-or-update>
	</el-card>
</template>

<script setup lang="ts">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { PagerOptions } from '@/hooks/pager'
import constant from '@/utils/constant'
import uri from '@/api/uri'
import addOrUpdate from './add-or-update.vue'
import { useRoute } from 'vue-router'
const route = useRoute()

const state: PagerOptions = reactive({
	isPage: false,
	dataListUrl:  route.path,
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: Number) => {
	addOrUpdateRef.value.init(uri,id)
}

const { getDataList, deleteHandle } = useCrud(state)
</script>
